﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ThucThe;
using DieuKhien;

namespace GiaoDien
{
    public partial class QL_Tour_sua : Form
    {
        
        public QL_Tour_sua()
        {
            InitializeComponent();
        }
        public void loadTour(Tour_thucthe tour, DiaDanh_thucthe dd, KhachSan_thucthe ks, NhaHang_thucthe nh, VanTai_thucthe vt)
        {
            txt_maTour.Text = tour.MaTour.ToString();
            txt_maTour.Enabled = false;
            txt_tenTour.Text = tour.TenTour;
            txt_giaCa.Text = tour.GiaCa.ToString();
            txt_moTa.Text = tour.MoTa;
            cbo_DiaDanh.Text = dd.TenDiaDanh;
            cbo_DiaDanh.SelectedValue = dd.MaDiaDanh;
            cbo_khachSan.Text = ks.TenKhachSan;
            cbo_khachSan.SelectedValue = ks.MaKhachSan;
            cbo_loaiHinh.Text = tour.LoaiHinh;
            cbo_nhaHang.Text = nh.TenNhaHang;
            cbo_nhaHang.SelectedValue = nh.MaNhaHang;
            txt_noiKhoiHanh.Text = tour.NoiKhoiHanh;
            cbo_vanTai.Text = vt.TenVanTai;
            cbo_vanTai.SelectedValue = vt.MaVanTai;
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                Tour_dieukhien tour_dk = new Tour_dieukhien();
                Tour_thucthe tour_tt = new Tour_thucthe();
                ChiTiet_Tour_DiaDanh t_dd_tt = new ChiTiet_Tour_DiaDanh();
                ChiTiet_Tour_KhachSan t_ks_tt = new ChiTiet_Tour_KhachSan();
                ChiTiet_Tour_NhaHang t_nh_tt = new ChiTiet_Tour_NhaHang();
                ChiTiet_Tour_VanTai t_vt_tt = new ChiTiet_Tour_VanTai();
                tour_tt.MaTour = txt_maTour.Text;
                t_dd_tt.MaDiaDanh = cbo_DiaDanh.SelectedIndex;
                t_nh_tt.MaNhaHang = cbo_nhaHang.SelectedIndex;
                t_ks_tt.MaKhachSan = cbo_khachSan.SelectedIndex;
                t_vt_tt.MaVanTai = cbo_vanTai.SelectedIndex;
                tour_tt.NoiKhoiHanh = txt_noiKhoiHanh.Text;
                tour_tt.TenTour = txt_tenTour.Text;
                tour_tt.GiaCa = long.Parse(txt_giaCa.Text.Trim());
                tour_dk.suaTour(tour_tt, t_dd_tt, t_ks_tt, t_nh_tt, t_vt_tt);
                MessageBox.Show("Sửa thành công.");
                this.Close();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Nhập đầy đủ các trường.", "Thêm tour");
            }
        }

        private void btn_reset_Click(object sender, EventArgs e)
        {
            txt_maTour.Text = "";
            txt_maTour.Enabled = false;
            txt_tenTour.Text = "";
            txt_giaCa.Text = "";
            txt_moTa.Text = "";
            cbo_DiaDanh.Text = "";
            cbo_khachSan.Text = "";
            cbo_loaiHinh.Text = "";
            cbo_nhaHang.Text = "";
            txt_noiKhoiHanh.Text = "";
            cbo_vanTai.Text = "";
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void QL_Tour_sua_Load(object sender, EventArgs e)
        {
            DiaDanh_dieukhien dd_dk = new DiaDanh_dieukhien();
            DiaDanh_thucthe dd_tt = new DiaDanh_thucthe();
            NhaHang_dieukhien nh_dk = new NhaHang_dieukhien();
            NhaHang_thucthe nh_tt = new NhaHang_thucthe();
            KhachSan_dieukhien ks_dk = new KhachSan_dieukhien();
            KhachHang_thucthe ks_tt = new KhachHang_thucthe();
            VanTai_dieukhien vt_dk = new VanTai_dieukhien();
            VanTai_thucthe vt_tt = new VanTai_thucthe();
            cbo_DiaDanh.DataSource = dd_dk.danhSachDiaDanh();
            cbo_DiaDanh.DisplayMember = "tenDiaDanh";
            cbo_DiaDanh.ValueMember = "maDiaDanh";
            cbo_khachSan.DataSource = ks_dk.danhSachKhachSan();
            cbo_khachSan.DisplayMember = "tenKhachSan";
            cbo_khachSan.ValueMember = "maKhachSan";
            cbo_nhaHang.DataSource = nh_dk.danhSachNhaHang();
            cbo_nhaHang.DisplayMember = "tenNhaHang";
            cbo_nhaHang.ValueMember = "maNhaHang";
            cbo_vanTai.DataSource = vt_dk.danhSachVanTai();
            cbo_vanTai.DisplayMember = "tenVanTai";
            cbo_vanTai.ValueMember = "maVanTai";
        }
    }
}
